package com.whw.fy.controller;

import com.whw.fy.entity.Message;
import com.whw.fy.entity.Pay;
import com.whw.fy.service.PayService;
import com.whw.fy.utils.GenIdUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

@Api(tags = "缴费记录模块")
@RestController
@RequestMapping("/api/pay")
public class PayController {

    @Resource
    private PayService payService;


    @ApiOperation(value = "新增缴费记录")
    @PostMapping("/one")
    public Message insert(Pay pay,int remindTimes){
        pay.setPayId(GenIdUtil.genPayId());
        pay.setPayTime(new Date());
        return payService.insertInUse(pay,remindTimes);
    }

    @ApiOperation(value = "根据id删除缴费记录")
    @DeleteMapping("/")
    public Message delete(String id){
        return payService.deleteByPrimaryKey(id);
    }

    @ApiOperation(value = "修改缴费记录")
    @PutMapping("/")
    public Message update(Pay pay){
        return payService.updateByPrimaryKeySelective(pay);
    }

    @ApiOperation(value = "根据id查看缴费记录")
    @GetMapping("/")
    public Message selectById(String id){
        return payService.selectByPrimaryKey(id);
    }

    @ApiOperation(value = "批量新增缴费记录")
    @PostMapping("/all")
    public Message batchInsert(List<Pay> list){
        return payService.batchInsert(list);
    }

    @ApiOperation(value = "获得所有缴费记录")
    @GetMapping("/all")
    public Message selectAll(){
        return payService.selectAll();
    }

    @ApiOperation(value = "根据学生id查询缴费记录")
    @GetMapping("/record")
    public Message selectPayByStudentId(Integer studentId) throws ParseException {
        return payService.selectAllByStudentId(studentId);
    }

    @ApiOperation(value = "根据家长id查询缴费记录")
    @GetMapping("/parentId")
    public Message selectByParentId(Integer parentId) throws ParseException {
        return payService.selectByParentId(parentId);
    }

}
